# 前端构建阶段
FROM node:18 as frontend
WORKDIR /app
COPY frontend/package.json frontend/pnpm-lock.yaml ./frontend/
RUN cd frontend && pnpm install
COPY frontend .
RUN pnpm build

# 后端构建阶段
FROM python:3.11-slim as backend
WORKDIR /app

# 设置工作目录
WORKDIR /app

# 复制后端文件
COPY backend/requirements.txt .

# 安装后端依赖
RUN pip install --no-cache-dir -r requirements.txt

# 复制后端代码
COPY backend .

# 生产镜像阶段
FROM python:3.11-slim
WORKDIR /app

# 复制前端构建产物
COPY --from=frontend /app/dist /app/frontend/dist

# 复制Python依赖
COPY --from=backend /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# 复制后端代码
COPY backend .

# 暴露端口
EXPOSE 5000

# 启动命令
# 安装uWSGI
RUN pip install uwsgi

# 启动命令
CMD ["uwsgi", "--ini", "uwsgi.ini", "--http-timeout", "600", "--buffer-size", "65536"]